//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#ifndef Green_PyConfig_H
#define Green_PyConfig_H

#include <memory>

#include "pybind11/pybind11.h"

#include "Config.h"
#include "Enums.h"
#include "Log.h"
#include "ThreadContext.h"

namespace py = pybind11;

namespace Green {

  PYBIND11_MODULE(Config, mod) {
    py::class_<Config, std::unique_ptr<Config, py::nodelete>>(mod, "Config")
      .def_static("getInstance", &Config::Instance, py::return_value_policy::reference, py::call_guard<ThreadContext>())
      .def("getLimitValue", &Config::LimitValue, py::call_guard<ThreadContext>())
      .def("setGlobalState", &Config::SetGlobalStateValue, py::call_guard<ThreadContext>())
      .def("setGlobalState", &Config::SetGlobalStateString, py::call_guard<ThreadContext>())
      .def("getGlobalState",
        [](const Config& rSelf, const EGlobalStateType globalStateType) -> py::object {
          bool exists = false;
          uint64 state_value = rSelf.GlobalStateValue(globalStateType, exists);
          if (exists) {
            return py::int_(state_value);
          }

          std::string state_str = rSelf.GlobalStateString(globalStateType, exists);
          if (exists) {
            return py::str(state_str);
          }

          LOG(warn) << "{PyConfig::getGlobalState} unset state \"" << EGlobalStateType_to_string(globalStateType) << "\"." << std::endl;
          return py::none();
        },
        py::call_guard<ThreadContext>())
      ;
  }

}

#endif  // Green_PyConfig_H
